<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
      </div>
      <div class="right-panel">
        <ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="content" placeholder="请输入消息内容"></ex-search>
      </div>
    </el-header>
    <el-main class="nopadding">
      <el-container>
        <el-main class="nopadding">
          <ex-table id="messageTable" ref="table" :columns="columns" :url="this.$API.system.message.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
        </el-main>
      </el-container>
    </el-main>
  </el-container>

  <save-dialog ref="saveDialog" @success="searchHandler"/>
  <view-dialog ref="viewDialog"/>

</template>

<script>
import saveDialog from './save'
import viewDialog from './view'
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import BaseTemplate from "@/utils/baseTemplate";

export default {
  name: '消息管理',
  components: {
    viewDialog,
    ExSearchTree,
    ExSearch,
    ExTable,
    saveDialog,
  },
  data() {
    return {
      buttons: [
        {name: this.$t('button.export'), icon: "el-icon-download", click: "export", permission: "export"},
      ],
      searches: [
        { type: "input", name: "标题", code: "title", placeholder: "请输入名称"},
        { type: "input", name: "内容", code: "content", placeholder: "请输入内容"},
        {type: "radio", name: "是否弹出", code: "isEject",dictCode:'IS_EJECT'},
        {type: "radio", name: "是否可用", code: "isEnabled",dictCode:'IS_ENABLED'},
      ],
      columns: [
        {code: "title", name: "标题", width: "",click:"show1"},
        {code: "content", name: "内容", width: ""},
        {code: "msgType", name: "消息类型", width: "", sortable: true, formatter: "DICT", key: "MSG_TYPE"},
        {code: "isEject", name: "是否弹出", width: "100", sortable: true, formatter: "DICT", key: "IS_EJECT"},
        {code: "isEnabled", name: "是否可用", width: "100", sortable: true, formatter: "DICT", key: "IS_ENABLED"},
        {code: "receiveObjectId", name: "接收人", width: "100", formatter: "DICT", key: "SysUser"},
        {code: "createUser", name: "创建人", width: "100", formatter: "DICT", key: "SysUser"},
        {code: "createTime", name: "创建时间", width: "175", sortable: true, formatter: "DATETIME"},

      ],
      parentLevelCode: null,
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    buttonHandler(index, name) {
      this.$options.methods[name](this, index);
    },
    async searchTreeHandler(data) {
      this.parentLevelCode = data.levelCode;
      let queryParams = {pathCode: this.parentLevelCode}
      await this.$refs.table.refresh(queryParams);
    },
    async searchHandler() {
      let queryParams = {pathCode: this.parentLevelCode}
      await this.$refs.table.refresh(queryParams);
    },
    columnClickHandler(name,data){
      this.$options.methods[name](this, data);
    },
    //查看
    show(_this) {
      let row = _this.$refs.table.selectionOne();
      if (!row) {
        return;
      }

      _this.$nextTick(() => {
        _this.$refs.viewDialog.open(row);
      })
    },
    //查看
    show1(_this,row) {
      _this.$nextTick(() => {
        _this.$refs.viewDialog.open(row);
      })
    },
    //导出
    async export(_this,index) {
      let attachParams = {};
      let exportApi = _this.$API.system.message.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
    },


  }
}
</script>
